package com.ac.api.component.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.ac.api.component.entity.CpBanner;
import com.ac.api.component.dao.CpBannerMapper;
import com.ac.api.component.service.CpBannerService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ac.utils.StringUtil;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author gjj
 * @since 2024-10-26
 */
@Service
public class CpBannerServiceImpl extends ServiceImpl<CpBannerMapper, CpBanner> implements CpBannerService {

    @Override
    public List<CpBanner> list(CpBanner example) {
        return this.list(buildWrapper(example));
    }

    @Override
    public IPage<CpBanner> page(CpBanner example, IPage page) {
        return this.page(page,buildWrapper(example));
    }

    /**
     * 构建查询
     *
     * @param example
     * @return
     */
    private QueryWrapper<CpBanner> buildWrapper(CpBanner example) {
        QueryWrapper<CpBanner> wrapper     = new QueryWrapper<>();
        wrapper.lambda()
                .like(StringUtil.isNotBlank(example.getName()),CpBanner::getName,example.getName())
                .eq(CpBanner::getState,"t")
                .orderByAsc(CpBanner::getOrderNum);
        return wrapper;
    }

}
